/**
 * Created by libb on 2016/10/24.
 */
$(document).ready(function () {
    var $Panelbar = $('#panelbar');
    //递归算法
    function recursion(items, $Parent) {
        var $Li = $('<li>');
        $Parent.append($Li);
        /*var $Span = $('<span>');
        $Li.append($Span);*/

        $.each(items, function (index, item) {
            if (index == 'MenuName') {
                $Li.append(item);
            }
            if (index == 'Icon') {
                var $Img = $('<img class="k-image" src="">');
                $Li.append($Img);
                $Img.attr('src', item);
            }
            if ($.isArray(item) && item.length > 0) {
                var $Ul = $('<ul>');
                $Li.append($Ul);
                for (var i = 0; i < item.length; i++) {
                    recursion(item[i], $Ul);
                }
            }
        });
    }

    $.each(menus, function (index, item) {
        recursion(item, $Panelbar);
    });

    $Panelbar.kendoPanelBar({
        expandMode: "single"
    });

    //1-Create the View-Model
    var viewModel = kendo.observable({
        isVisible: true,
        onSelect: function (e) {
            var len = $(e.item).children().length;
            if(len<=1){
                alert('最后一层了，下面没有了！');
            }
        }
    });
    //3-Bind the View to the View-Model
    kendo.bind($Panelbar, viewModel);
});